﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SpotsHub.RouteService.Data
{
    [Table("Route_Address")]
    public class Address : EntityBase
    {
        #region Required

        [Required]
        public string Address1 { get; set; }

        [Required]
        public int CityId { get; set; }

        [Required]
        public int StateProvinceId { get; set; }

        [Required]
        public int CountryId { get; set; }

        #endregion

        #region Navigator

        public virtual Locality City { get; set; }

        public virtual StateProvince StateProvince { get; set; }

        public virtual Country Country { get; set; }

        #endregion

        #region Others

        public double? Latitude { get; set; }

        public double? Longitude { get; set; }

        public string ZipPostalCode { get; set; }

        public string Address2 { get; set; }

        public string AdminDistrict2 { get; set; }

        public string FirstName { get; set; }

        public string LastName { get; set; }

        public string Email { get; set; }

        public string Company { get; set; }
        
        public string PhoneNumber { get; set; }

        public string PhoneNumber2 { get; set; }

        public string FaxNumber { get; set; }

        public DateTime? CreatedOnUtc { get; set; }

        #endregion

        #region Helper

        [NotMapped]
        public virtual string FormattedAddress
        {
            get
            {
                string address = Address2 == null ? Address1 : String.Format("{0} {1}", Address1, Address2);
                string city = City.Name;
                string province = StateProvince.Name;
                //string country = Country.Name;
                return ZipPostalCode == null ?
                    String.Format("{0}, {1}, {2}", address, city, province) :
                    String.Format("{0}, {1}, {2} {3}", address, city, province, ZipPostalCode);
            }
        }

        #endregion
    }

    [Table("Route_Localities")]
    public class Locality : EntityWithNameBase
    {
        public virtual List<Address> Addresses { get; set; }
    }

    [Table("Route_Provinces")]
    public class StateProvince : EntityWithNameBase
    {
        public virtual List<Address> Addresses { get; set; }
    }

    [Table("Route_Counties")]
    public class Country : EntityWithNameBase
    {
        public virtual List<Address> Addresses { get; set; }
    }

    //[Table("Route_PostCode")]
    //public class PostCodes
    //{
    //    [Key]
    //    public string Name { get; set; }
    //    public virtual List<Address> Addresses { get; set; }
    //}

    //[ComplexType]
    //public class GeocodePoint
    //{
    //    public double? Latitude { get; set; }
    //    public double? Longitude { get; set; }
    //}

    //public enum Cities
    //{
    //    Burnaby,
    //    Richmond,
    //    Vancouver,
    //    NorthVancouver,
    //    Surrey
    //}

    //public enum Provinces
    //{
    //    BC
    //}

    //public enum Counties
    //{
    //    Canada
    //}
}
